import base64
import os
import streamlit as st
def get_base64_image(image_path):
    """将图片转换为 base64 编码"""
    try:
        # 使用相对于 app.py 的路径
        current_dir = os.path.dirname(__file__)
        image_path = os.path.join(current_dir, image_path)
        
        if not os.path.exists(image_path):
            st.error(f"图片文件不存在: {image_path}")
            return ""
            
        with open(image_path, "rb") as img_file:
            return base64.b64encode(img_file.read()).decode()
    except Exception as e:
        st.error(f"读取图片失败: {str(e)}")
        return ""